<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>NetJava-任务管理系统v1.0-任务处理</title>
<style type="text/css" media="all">
    .allow-float {clear:none!important;} /* 允许该元素浮动 */
    .stop-float {clear:both!important;} /* 阻止该元素浮动 */
	.float-left {float:left;padding-left:5px}   /*浮动到左边*/
  </style>


<script type="text/javascript">
Ext.onReady(function(){
Ext.BLANK_IMAGE_URL = '/taskManager05/ext/resources/images/default/s.gif';

    Ext.QuickTips.init();

    Ext.form.Field.prototype.msgTarget = 'side';
   var form1 = new Ext.form.FormPanel({
			title:'任务查询',
			labelSeparator :'：',//分隔符
			labelWidth : 80,//标签宽度
			bodyStyle:'padding:5',//表单边距
			frame : true,
			collapsible: true,
			height:80,
			width:window.screen.width-230,
			applyTo :'form1',
			items:[

				new Ext.form.TextField({
					fieldLabel : '项目名称',
					id : 'userName',
					width:(window.screen.width-320)*0.18,
					itemCls:'float-left',//向左浮动
					clearCls:'allow-float',//允许浮动
					selectOnFocus : true,//得到焦点时自动选择文本
					allowBlank : true
				}),

				new Ext.form.DateField({
					fieldLabel : '开始时间',
					format:'Y年m月d日',
					id : 'starttime',
					width:(window.screen.width-320)*0.18,
					itemCls:'float-left',//向左浮动
					clearCls:'allow-float',//允许浮动
					allowBlank : true
				}),
				new Ext.form.DateField({
					fieldLabel : '结束时间',
					format:'Y年m月d日',
					id : 'endtime',
					width:(window.screen.width-320)*0.18,
					itemCls:'float-left',//向左浮动
					clearCls:'allow-float',//允许浮动
					allowBlank : true
				}),
				new Ext.Button({
					text : '开始查询',
					itemCls:'float-left',//向左浮动
					clearCls:'allow-float',//允许浮动
					handler : submitMsg
				})
			]

		})
	function submitMsg(){
		form1.form.submit({
			clientValidation:true,//进行客户端验证
			waitMsg:'正在进行查询，请稍候...',//提示信息
			waitTitle:'提示',
			url:'selectObject.jsp',
			method:'POST',
			success:function(){//加载成功处理函数
				Ext.Msg.alert('查询完毕！');
			},
			failure:function(form,action){//加载失败处理函数
			Ext.Msg.alert('提示','查询失败，原因：'+action.failureType);
			}
		});
	}


		var recordType = Ext.data.Record.create([
           {name: "id",mapping:"id"},
           {name: "programName",mapping: "programName",type : 'string'},
           {name: "inserttime",mapping:"inserttime", type: "string"},
           {name: "starttime",mapping:"starttime", type: "string"},
           {name: "endtime",mapping:"endtime", type: "string"},
           {name: "insertuser",mapping:"insertuser", type: "string"},
           {name: "destuser",mapping:"destuser", type: "string"},
           {name: "flag",mapping:"flag", type: "string"}
  ]);

		//调DWR取得数据

		var store = new Ext.data.Store({
			proxy : new Ext.data.DWRProxy(ProgramUtil.getAllProgram,true),
			reader : new Ext.data.ListRangeReader({
						totalProperty: 'totalSize',
						root : 'data',
						id: 'id'
						},recordType),
			remoteSort: true
		});
		store.load({
			params:{
				start:0,
				limit:5
				}
			});

	//创建工具栏组件
		var toolbar = new Ext.Toolbar([
			{text : '添加任务',iconCls:'add',handler : addProgram},
			{text : '修改任务',iconCls:'option'},
			{text : '删除任务',iconCls:'remove'}
		]);

		//分页工具栏
		var pagebar = new Ext.PagingToolbar({
			store : store,
			pageSize : 5,
			displayInfo : true,
			displayMsg : '第 {0} ~ {1} 条 共 {2} 条',
			emptyMsg : '当前没有记录'
		});


		//创建选择模式对象
	var cb = new Ext.grid.CheckboxSelectionModel()
	//创建Grid表格组件
	var grid = new Ext.grid.GridPanel({
			renderTo : 'grid-div',
			frame : true,
			tbar : toolbar,
			bbar : pagebar,
			loadMask: true,    //是否显示正在加载
			store : store,
			height : 320,
			width : window.screen.width-230,
			stripeRows : true,
			autoScroll : true,
			viewConfig : {autoFill : true},
			sm : cb,
			columns: [//配置表格列
				new Ext.grid.RowNumberer({
					header : '行号',
					width : 40
				}),
				cb,
				{header: "任务编号", width: 45, dataIndex: 'id', sortable: true},
				{header: "任务名称", width: 75, dataIndex: 'programName', sortable: true},
				{header: "发布时间", width: 75, dataIndex: 'inserttime', sortable: true},
				{header: "任务开始时间", width: 75, dataIndex: 'starttime', sortable: true},
				{header: "任务结束时间", width: 75, dataIndex: 'endtime', sortable: true},
				{header: "发布人", width: 75, dataIndex: 'insertuser', sortable: true},
				{header: "执行人", width: 75, dataIndex: 'destuser', sortable: true},
				{header: "任务状态", width: 75, dataIndex: 'flag', sortable: true}
				]
		});


});



		var ProgramForm = new Ext.FormPanel({
			labelSeparator : "：",
			frame:true,
			border:false,
			items : [
				{
					xtype:'datefield',
					width : 200,
					name : 'inserttime',
					format:'Y年m月d日',
					value : new Date()

				},{
					xtype:'textfield',
					width : 200,
					allowBlank : false,
					blankText : '任务名称不能为空',
					name : 'programName',
					fieldLabel:'任务名称'
				},{
					xtype:'datefield',
					width : 200,
					format:'Y年m月d日',
					name : 'starttime',
					fieldLabel:'任务开始时间'
				},{
					xtype:'datefield',
					width : 200,
					format:'Y年m月d日',
					name : 'endtime',
					fieldLabel:'任务结束时间'
				},{
					xtype:'combo',
					width : 200,
					name : 'destuser',
					fieldLabel:'执行人',
					store : new Ext.data.Store({
							proxy : new Ext.data.DWRProxy(UserList.getAllUser,true),
							render : new Ext.data.ListRangeReader(
								{
									totalProperty : 'userNum',
									root : 'usredata',
									id : 'id'
								},
								new Ext.data.Record.create([
									    {name: 'id', mapping:'id',type : 'string'},
									    {name: 'username',mapping:'username', type: 'string'}
									])
								)
						}),
					displayField : 'username', //定义要显示的字段
					valueField : 'id',//定义值的字段
					loadingText : '正在加载用户列表',
					triggerAction : 'all',//单击出发按钮显示所有数据
					typeAhead : true,//允许自动选择匹配剩余的部分文本
					resizable : true,//允许改变下拉列表的大小
					forceSelection : true,//要求输入的值必须在列表中存在
					mode : 'remote',//远程模式
					emptyText : '请选择任务接收人',
					selectOnFoucs : true

				},{
					xtype:'textarea',
					width : 200,
					name : 'programdesc',
					fieldLabel:'任务简介'
				}

			],
			buttons:[
				{
					text : '关闭',
					handler : function(){
						win.hide();
					}
				},{
					text : '提交',
					handler : submitForm
				}
			]
		});
		//创建弹出窗口
		var win = new Ext.Window({
			layout:'fit',
		    width:380,
		    closeAction:'hide',
		    height:280,
			resizable : false,
			shadow : true,
			modal :true,
		    closable:true,
		    bodyStyle:'padding:5 5 5 5',
		    animCollapse:true,
			items:[ProgramForm]
		});
		var addProgram =function addProgram(){
			ProgramForm.form.reset();
			ProgramForm.isAdd = true;
			win.setTitle("添加新任务");
			win.show();


		};
		function submitForm(){
			//判断当前执行的提交操作
				ProgramForm.form.submit({
					clientValidation:true,//进行客户端验证
					waitMsg : '正在提交数据请稍后',//提示信息
					waitTitle : '提示',//标题
					url : 'addprogram',//请求的url地址
					method:'POST',//请求方式
					success:function(form,action){//加载成功的处理函数
						win.hide();
						updateBookList(action.result.bookId);
						Ext.Msg.alert('提示','添加任务成功');
					},
					failure:function(form,action){//加载失败的处理函数
						Ext.Msg.alert('提示','添加任务失败');
					}
				});
			}
</script>
</head>
<body>
<table><tr><td>
<div id='form1' style="margin:8px 8px 4px 8px"></div>
</td></tr>
</table>
<div id='grid-div' style="margin:4px 8px 8px 8px"></div>


</body>
</html>